﻿#include "library.au3"

Global $win = "League of Legends (TM) Client"
Global $hWnd = WinActivate($win)
Global $winPos = WinGetPos($win)

Global $attackSpeed = 0.72
Global $attackBonus = 0.05
Global $shotRatio = 0.3
Global $range = 330
Global $height = 50

Global $keyAPressed = 0
Global $keyBPressed = 0
Global $keyCPressed = 0
Global $keyDPressed = 0
Global $keyEPressed = 0
Global $keyFPressed = 0

Global $movingShotTimer1 = TimerInit()
Global $movingShotTimer2 = TimerInit()
Global $movingShotState = 0

FFSetWnd($hWnd, False)

While True
   $hWnd = WinActive($win)
   If $hWnd = 0 Then
	  Sleep(100)
	  ContinueLoop
   EndIf

   Local $hDLL = DllOpen("user32.dll")

   If _IsPressed("02", $hDLL) = 1 Then
	  If _IsPressed("A0", $hDLL) = 1 Then
		 MovingShotAttack()
	  Else
		 MovingShotEnemy()
	  EndIf

	  $keyAPressed = 1
   Else
	  If $keyAPressed = 1 Then
		 ;Send("s")
	  EndIf

	  $keyAPressed = 0
   EndIf

   If _IsPressed("21", $hDLL) = 1 Then
	  If $keyCPressed = 0 Then
		 $attackSpeed = $attackSpeed + 0.02
		 ToolTip("attackSpeed : " & $attackSpeed, $winPos[0] + 100, $winPos[1] + 5)
	  EndIf
	  $keyCPressed = 1
   Else
	  $keyCPressed = 0
   EndIf

   If _IsPressed("22", $hDLL) = 1 Then
	  If $keyDPressed = 0 Then
		 $attackSpeed = $attackSpeed - 0.02
		 ToolTip("attackSpeed : " & $attackSpeed, $winPos[0] + 100, $winPos[1] + 5)
	  EndIf
	  $keyDPressed = 1
   Else
	  $keyDPressed = 0
   EndIf

   If _IsPressed("2D", $hDLL) = 1 Then
	  If $keyEPressed = 0 Then
		 $range = $range + 5
		 ToolTip("range : " & $range, $winPos[0] + 100, $winPos[1] + 5)
	  EndIf
	  $keyEPressed = 1
   Else
	  $keyEPressed = 0
   EndIf

   If _IsPressed("2E", $hDLL) = 1 Then
	  If $keyFPressed = 0 Then
		 $range = $range - 5
		 ToolTip("range : " & $range, $winPos[0] + 100, $winPos[1] + 5)
	  EndIf
	  $keyFPressed = 1
   Else
	  $keyFPressed = 0
   EndIf

   DllClose($hDLL)
WEnd

Func MovingShotEnemy()
   Local $shotDelay = 1000 / ($attackSpeed + $attackBonus)

   Switch $movingShotState
   Case 0
	  If (TimerDiff($movingShotTimer1) > $shotDelay) Then
		 FFSnapShot(50, 50, $winPos[2] - 50, $winPos[3] - 120)

		 Local $heroPos[2]
		 Local $heroFind = FindHero($heroPos[0], $heroPos[1], $hWnd)

		 Local $enemyPos[2]
		 Local $enemyFind = FindEnemy($enemyPos[0], $enemyPos[1], $hWnd)

		 ; ToolTip("Hero:"&$heroPos[0]&","&$heroPos[1]&" Enemy:"&$enemyPos[0]&","&$enemyPos[1], $winPos[0] + 100, $winPos[1] + 5)

		 Local $curRange = 0
		 Local $curDist = 0
		 Local $checkRange = CheckRange($heroPos[0], $heroPos[1], $enemyPos[0], $enemyPos[1], $range, $height, $curRange, $curDist)
		 ; ToolTip("curRange:"&Int($curRange)&" curDist:"&Int($curDist), $winPos[0] + 100, $winPos[1] + 5)

		 If ($heroFind And $enemyFind And $checkRange) Then
			Local $mousePos = MouseGetPos()
			Send("a")
			Send("{` DOWN}")
			MouseClick("left", $enemyPos[0], $enemyPos[1], 1, 0)
			Send("{` UP}")
			MouseMove($mousePos[0], $mousePos[1], 0)

			$movingShotTimer1 = TimerInit()
			$movingShotState = 1
		 Else
			If (TimerDiff($movingShotTimer2) > 150) Then
			   Send("a{` DOWN}{SPACE}{` UP}")

			   $movingShotTimer2 = TimerInit()
			EndIf
		 EndIf
	  Else
		 If (TimerDiff($movingShotTimer2) > 150) Then
			Send("a{` DOWN}{SPACE}{` UP}")

			$movingShotTimer2 = TimerInit()
		 EndIf
	  EndIf
   Case 1
	  If (TimerDiff($movingShotTimer1) > $shotDelay * $shotRatio) Then
		 $movingShotTimer2 = TimerInit()
		 $movingShotState = 0

		 MovingShotEnemy()
	  EndIf
   EndSwitch
EndFunc

Func MovingShotAttack()
   Local $shotDelay = 1000 / ($attackSpeed + $attackBonus)

   Switch $movingShotState
   Case 0
	  If (TimerDiff($movingShotTimer1) > $shotDelay) Then
		 $movingShotTimer1 = TimerInit()
		 $movingShotState = 1
	  EndIf
   Case 1
	  If (TimerDiff($movingShotTimer1) > $shotDelay * $shotRatio) Then
		 $movingShotTimer2 = TimerInit()
		 $movingShotState = 0
	  EndIf
   EndSwitch
EndFunc
